Return to start page
Systems/World/Struct Weather.j
1 library AStructSystemsWorldWeather requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, AStructCoreGeneralVector
2
3 struct AWeather
4 public static constant integer weatherTypeAshenvaleRainHeavy = 0
5 public static constant integer weatherTypeAshenvaleRainLight = 1
6 public static constant integer weatherTypeDalaranShield = 2
7 public static constant integer weatherTypeBlueDungeonFogHeavy = 3
8 public static constant integer weatherTypeBlueDungeonFogLight = 4
9 public static constant integer weatherTypeGreenDungeonFogHeavy = 5
10 public static constant integer weatherTypeGreenDungeonFogLight = 6
11 public static constant integer weatherTypeRedDungeonFogHeavy = 7
12 public static constant integer weatherTypeRedDungeonFogLight = 8
13 public static constant integer weatherTypeWhiteDungeonFogHeavy = 9
14 public static constant integer weatherTypeWhiteDungeonFogLight = 10
15 public static constant integer weatherTypeLordaeronRainHeavy = 11
16 public static constant integer weatherTypeLordaeronRainLight = 12
17 public static constant integer weatherTypeNorhtrendBlizzard = 13
18 public static constant integer weatherTypeNorhtrendSnowfallHeavy = 14
19 public static constant integer weatherTypeNorhtrendSnowfallLight = 15
20 public static constant integer weatherTypeForeignCountryWindHeavy = 16
21 public static constant integer weatherTypeForeignCountryWindLight = 17
22 public static constant integer weatherTypeRays = 18
23 public static constant integer weatherTypeRaysOfMoonlight = 19
24 public static constant integer weatherTypeWindHeavy = 20
25 public static constant integer weatherTypeNoWeather = 21
26 private static constant integer maxWeatherTypes = 22
27 //static start members
28 private static integer array m_weatherTypeEffectId[thistype.maxWeatherTypes]
29 private static string array m_skyModelFile[thistype.maxWeatherTypes]
30 //dynamic members
31 private real m_minimumChangeTime
32 private real m_maximumChangeTime
33 private boolean m_changeSky
34 private boolean array m_isWeatherTypeAllowed[thistype.maxWeatherTypes]
35 //members
36 private region m_region
37 private timer m_changeTimer
38 private ARectVector m_rects
39 private AWeatherEffectVector m_weatherEffects
40
41 //! runtextmacro optional A_STRUCT_DEBUG("\"AWeather\"")
42
43 //dynamic mebers
44
45 public method setMinimumChangeTime takes real minimumChangeTime returns nothing
46 set this.m_minimumChangeTime = minimumChangeTime
47 endmethod
48
49 public method minimumChangeTime takes nothing returns real
50 return this.m_minimumChangeTime
51 endmethod
52
53 public method setMaximumChangeTime takes real minimumChangeTime returns nothing
54 set this.m_maximumChangeTime = minimumChangeTime
55 endmethod
56
57 public method maximumChangeTime takes nothing returns real
58 return this.m_maximumChangeTime
59 endmethod
60
61 public method setChangeSky takes boolean changeSky returns nothing
62 set this.m_changeSky = changeSky
63 endmethod
64
65 public method changeSky takes nothing returns boolean
66 return this.m_changeSky
67 endmethod
68
69 public method setWeatherTypeAllowed takes integer weatherType, boolean allowed returns nothing
70 set this.m_isWeatherTypeAllowed[weatherType] = allowed
71 endmethod
72
73 public method isWeatherTypeAllowed takes integer weatherType returns boolean
74 return this.m_isWeatherTypeAllowed[weatherType]
75 endmethod
76
77 //methods
78
79 /// Rects are not removed by this struct!
80 public method addRect takes rect usedRect returns integer
81 call this.m_rects.pushBack(usedRect)
82 call this.m_weatherEffects.pushBack(null)
83 return this.m_rects.backIndex()
84 endmethod
85
86 public method removeRect takes rect usedRect returns nothing
87 local integer index = this.m_rects.find(usedRect)
88 if (index == -1) then
89 return
90 endif
91 call this.removeRectByIndex(index)
92 endmethod
93
94 public method removeRectByIndex takes integer index returns nothing
95 call this.m_rects.erase(index)
96 if (this.m_weatherEffects[index] != null) then
97 call RemoveWeatherEffect(this.m_weatherEffects[index])
98 set this.m_weatherEffects[index] = null
99 endif
100 call this.m_weatherEffects.erase(index)
101 endmethod
102
103 public method setAllWeatherTypesAllowed takes boolean allowed returns nothing
104 local integer i = 0
105 loop
106 exitwhen (i == thistype.maxWeatherTypes)
107 set this.m_isWeatherTypeAllowed[i] = allowed
108 set i = i + 1
109 endloop
110 endmethod
111
112 public method setEnabled takes boolean enabled returns nothing
113 local integer i = 0
114 loop
115 exitwhen (i == this.m_rects.size())
116 if (this.m_weatherEffects[i] != null) then
117 call EnableWeatherEffect(this.m_weatherEffects[i], enabled)
118 endif
119 set i = i + 1
120 endloop
121 if (enabled) then
122 call ResumeTimer(this.m_changeTimer)
123 else
124 call PauseTimer(this.m_changeTimer)
125 endif
126 endmethod
127
128 public method changeWeather takes integer weatherType returns nothing
129 local integer i = 0
130 loop
131 exitwhen (i == this.m_rects.size())
132 if (this.m_weatherEffects[i] != null) then
133 call RemoveWeatherEffect(this.m_weatherEffects[i])
134 set this.m_weatherEffects[i] = null
135 endif
136 if (thistype.m_weatherTypeEffectId[weatherType] != 0) then
137 set this.m_weatherEffects[i] = AddWeatherEffect(this.m_rects[i], thistype.m_weatherTypeEffectId[weatherType])
138 call EnableWeatherEffect(this.m_weatherEffects[i], true)
139 endif
140 set i = i + 1
141 endloop
142 if (this.m_changeSky) then
143 call SetSkyModel(thistype.m_skyModelFile[weatherType])
144 endif
145 endmethod
146
147 private static method timerFunctionChangeWeather takes nothing returns nothing
148 local timer expiredTimer = GetExpiredTimer()
149 local thistype this = AHashTable.global().handleInteger(expiredTimer, "this")
150 local integer array possibleWeatherTypes
151 local integer maxPossibleWeatherTypes = 0
152 local integer i = 0
153 loop
154 exitwhen (i == thistype.maxWeatherTypes)
155 if (this.m_isWeatherTypeAllowed[i]) then
156 set possibleWeatherTypes[maxPossibleWeatherTypes] = i
157 set maxPossibleWeatherTypes = maxPossibleWeatherTypes + 1
158 endif
159 set i = i + 1
160 endloop
161 call this.changeWeather(possibleWeatherTypes[GetRandomInt(0, maxPossibleWeatherTypes - 1)])
162 call this.start() //start again with new time
163 set expiredTimer = null
164 endmethod
165
166 /// Make sure that you've set minimum and maximum change time before!
167 public method start takes nothing returns nothing
168 call TimerStart(this.m_changeTimer, GetRandomReal(this.m_minimumChangeTime, this.m_maximumChangeTime), false, function thistype.timerFunctionChangeWeather)
169 endmethod
170
171 public static method create takes nothing returns thistype
172 local thistype this = thistype.allocate()
173 //dynamic members
174 set this.m_changeSky = false
175 //members
176 set this.m_region = CreateRegion()
177 set this.m_changeTimer = CreateTimer()
178 call AHashTable.global().setHandleInteger(this.m_changeTimer, "this", this)
179 set this.m_rects = ARectVector.create()
180 set this.m_weatherEffects = AWeatherEffectVector.create()
181
182 return this
183 endmethod
184
185 private method removeWeatherEffects takes nothing returns nothing
186 local integer i = 0
187 loop
188 exitwhen (i == this.m_weatherEffects.size())
189 if (this.m_weatherEffects[i] != null) then
190 call RemoveWeatherEffect(this.m_weatherEffects[i])
191 set this.m_weatherEffects[i] = null
192 endif
193 set i = i + 1
194 endloop
195 call this.m_weatherEffects.destroy()
196 endmethod
197
198 public method onDestroy takes nothing returns nothing
199 //members
200 call RemoveRegion(this.m_region)
201 set this.m_region = null
202 call AHashTable.global().destroyTimer(this.m_changeTimer)
203 set this.m_changeTimer = null
204 call this.m_rects.destroy() // DO NOT REMOVE RECTS, there were set by user
205 call this.removeWeatherEffects()
206 endmethod
207
208 /// @todo Set all sky types (maybe add custom skies)
209 public static method init takes nothing returns nothing
210 //static start members
211 set thistype.m_weatherTypeEffectId[thistype.weatherTypeAshenvaleRainHeavy] = 'RAhr'
212 set thistype.m_skyModelFile[thistype.weatherTypeAshenvaleRainHeavy] = ""
213 set thistype.m_weatherTypeEffectId[thistype.weatherTypeAshenvaleRainLight] = 'RAlr'
214 set thistype.m_skyModelFile[thistype.weatherTypeAshenvaleRainLight] = ""
215 set thistype.m_weatherTypeEffectId[thistype.weatherTypeDalaranShield] = 'MEds'
216 set thistype.m_skyModelFile[thistype.weatherTypeDalaranShield] = "Environment\\Sky\\DalaranSky\\DalaranSky.mdl"
217 set thistype.m_weatherTypeEffectId[thistype.weatherTypeBlueDungeonFogHeavy] = 'FDbh'
218 set thistype.m_skyModelFile[thistype.weatherTypeBlueDungeonFogHeavy] = ""
219 set thistype.m_weatherTypeEffectId[thistype.weatherTypeBlueDungeonFogLight] = 'FDbl'
220 set thistype.m_skyModelFile[thistype.weatherTypeBlueDungeonFogLight] = ""
221 set thistype.m_weatherTypeEffectId[thistype.weatherTypeGreenDungeonFogHeavy] = 'FDgh'
222 set thistype.m_skyModelFile[thistype.weatherTypeGreenDungeonFogHeavy] = ""
223 set thistype.m_weatherTypeEffectId[thistype.weatherTypeGreenDungeonFogLight] = 'FDgl'
224 set thistype.m_skyModelFile[thistype.weatherTypeGreenDungeonFogLight] = ""
225 set thistype.m_weatherTypeEffectId[thistype.weatherTypeRedDungeonFogHeavy] = 'FDrh'
226 set thistype.m_skyModelFile[thistype.weatherTypeRedDungeonFogHeavy] = ""
227 set thistype.m_weatherTypeEffectId[thistype.weatherTypeRedDungeonFogLight] = 'FDrl'
228 set thistype.m_skyModelFile[thistype.weatherTypeRedDungeonFogLight] = ""
229 set thistype.m_weatherTypeEffectId[thistype.weatherTypeWhiteDungeonFogHeavy] = 'FDwh'
230 set thistype.m_skyModelFile[thistype.weatherTypeWhiteDungeonFogHeavy] = ""
231 set thistype.m_weatherTypeEffectId[thistype.weatherTypeWhiteDungeonFogLight] = 'FDwl'
232 set thistype.m_skyModelFile[thistype.weatherTypeWhiteDungeonFogLight] = ""
233 set thistype.m_weatherTypeEffectId[thistype.weatherTypeLordaeronRainHeavy] = 'RLhr'
234 set thistype.m_skyModelFile[thistype.weatherTypeLordaeronRainHeavy] = ""
235 set thistype.m_weatherTypeEffectId[thistype.weatherTypeLordaeronRainLight] = 'RLlr'
236 set thistype.m_skyModelFile[thistype.weatherTypeLordaeronRainLight] = ""
237 set thistype.m_weatherTypeEffectId[thistype.weatherTypeNorhtrendBlizzard] = 'SNbs'
238 set thistype.m_skyModelFile[thistype.weatherTypeNorhtrendBlizzard] = "Environment\\Sky\\BlizzardSky\\BlizzardSky.mdl"
239 set thistype.m_weatherTypeEffectId[thistype.weatherTypeNorhtrendSnowfallHeavy] = 'SNhs'
240 set thistype.m_skyModelFile[thistype.weatherTypeNorhtrendSnowfallHeavy] = ""
241 set thistype.m_weatherTypeEffectId[thistype.weatherTypeNorhtrendSnowfallLight] = 'SNls'
242 set thistype.m_skyModelFile[thistype.weatherTypeNorhtrendSnowfallLight] = ""
243 set thistype.m_weatherTypeEffectId[thistype.weatherTypeForeignCountryWindHeavy] = 'WOcw'
244 set thistype.m_skyModelFile[thistype.weatherTypeForeignCountryWindHeavy] = "Environment\\Sky\\Outland_Sky\\Outland_Sky.mdl"
245 set thistype.m_weatherTypeEffectId[thistype.weatherTypeForeignCountryWindLight] = 'WOlw'
246 set thistype.m_skyModelFile[thistype.weatherTypeForeignCountryWindLight] = "Environment\\Sky\\Outland_Sky\\Outland_Sky.mdl"
247 set thistype.m_weatherTypeEffectId[thistype.weatherTypeRays] = 'LRaa'
248 set thistype.m_skyModelFile[thistype.weatherTypeRays] = "Environment\\Sky\\LordaeronSummerSky\\LordaeronSummerSky.mdl"
249 set thistype.m_weatherTypeEffectId[thistype.weatherTypeRaysOfMoonlight] = 'LRma'
250 set thistype.m_skyModelFile[thistype.weatherTypeRaysOfMoonlight] = "Environment\\Sky\\LordaeronSummerSky\\LordaeronSummerSky.mdl"
251 set thistype.m_weatherTypeEffectId[thistype.weatherTypeWindHeavy] = 'WNcw'
252 set thistype.m_skyModelFile[thistype.weatherTypeWindHeavy] = "Environment\\Sky\\LordaeronSummerSky\\LordaeronSummerSky.mdl"
253 set thistype.m_weatherTypeEffectId[thistype.weatherTypeNoWeather] = 0
254 set thistype.m_skyModelFile[thistype.weatherTypeNoWeather] = "Environment\\Sky\\Sky\\SkyLight.mdl"
255 endmethod
256 endstruct
257
258 endlibrary